<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改仪器')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-instrument-edit" th:object="${zkInstrument}">
        <input name="instId" th:field="*{instId}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">HostId：</label>
            <div class="col-sm-8">
                <input name="hostId" th:field="*{hostId}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">名称：</label>
            <div class="col-sm-8">
                <input name="instName" th:field="*{instName}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">生产商名称：</label>
            <div class="col-sm-8">
                <input name="company" th:field="*{company}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">生产日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="prodData" th:value="${#dates.format(zkInstrument.prodData, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">型号：</label>
            <div class="col-sm-8">
                <input name="type" th:field="*{type}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">样品总数：</label>
            <div class="col-sm-8">
                <input name="sampleTotal" th:field="*{sampleTotal}" class="form-control" type="number">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <label class="toggle-switch switch-solid">
                    <input type="checkbox" id="status" th:checked="*{isLock == 0}">
                    <span></span>
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">公告：</label>
            <div class="col-sm-8">
                <textarea name="notice" class="form-control">[[*{notice}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "system/instrument";
    $("#form-instrument-edit").validate({
        onkeyup: false,
        rules:{
            hostId: {
                remote: {
                    url: prefix + "/checkHostIdUnique",
                    type: "post",
                    datatype: "json",
                    data: {
                        "instId": function () {
                            return $("#instId").val();
                        },
                        "hostId": function () {
                            return $("#hostId").val();
                        }
                    }
                }
            },
            instName: {
                remote: {
                    url: prefix + "/checkInstNameUnique",
                    type: "post",
                    datatype: "json",
                    data: {
                        "instId": function () {
                            return $("#instId").val();
                        },
                        "instName": function () {
                            return $.common.trim($("#instName").val())
                        }
                    }
                }
            }
        },
        messages: {
            "hostId": {
                remote: "hostId已经存在"
            },
            "instName": {
                remote: "仪器名称已经存在"
            }
        },
        focusCleanup: true
    });

    $("input[name='prodData']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $('#form-instrument-edit').serializeArray();
            var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
            data.push({"name": "status", "value": status});
            $.operate.save(prefix + "/edit", data);
        }
    }
</script>
</body>
</html>